package com.good.http;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class HttpConnectionManager {

    public static Map<String,HttpConnectionPool> httpManager=new ConcurrentHashMap<>();

    public static HttpConnectionPool getConnectionPool(String poolName){
        HttpConnectionPool httpConnectionPool = httpManager.get(poolName);
        if(null == httpConnectionPool ){
            synchronized (HttpConnectionManager.class){
                httpConnectionPool=addHttpConnectionPool(poolName);
                httpConnectionPool.init();
            }
        }
        return httpConnectionPool;
    }

    private static synchronized HttpConnectionPool addHttpConnectionPool(String poolName){
        HttpConnectionPool rtv = httpManager.get(poolName);
        if(null != rtv){
            return rtv;
        }

        rtv = new HttpConnectionPool(poolName);

        httpManager.put(poolName, rtv);

        return rtv;
    }
}
